﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Text;
using System.Collections;
using System.Xml;
using System.Web.Services;
using FileManager;

public partial class SJZD_NameManage : ATPages
{
    Function f = new Function();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            HFroid.Value = Request.Cookies["user"].Values["roleid"];
            initGvData();
            lblPath.Text = f.getModuleidAdd(Request.QueryString["moduid"]);//当前位置
            hfxs.Value = Request.QueryString["moduid"];//栏目ID
            ComoditiesType.Text = Request.QueryString["ComoditiesType"];
            Specifications.Text = Request.QueryString["Specifications"];
            ComoditiesName.Text = Request.QueryString["ComoditiesName"];
            Brand.Text = Request.QueryString["Brand"];
            modulbh.Text = Request.QueryString["modulbh"];
            FactNum.SelectedValue = Request.QueryString["FactNum"];
            countStock.SelectedValue = Request.QueryString["countStock"];
        }
    }
    private void initGvData()
    {
        string search = "";
        string sql = " select * from VIEW价格管理组合表 WHERE 1 = 1  ";

        if (!string.IsNullOrEmpty(Request.QueryString["ComoditiesType"]))
        {
            search += "&ComoditiesType=" + Request.QueryString["ComoditiesType"];
            sql += " and ComoditiesType like '%" + Request.QueryString["ComoditiesType"] + "%'";
        }
        if (!string.IsNullOrEmpty(Request.QueryString["Specifications"]))
        {
            search += "&Specifications=" + Request.QueryString["Specifications"];
            sql += " and Specifications like '%" + Request.QueryString["Specifications"] + "%'";
        }
        if (!string.IsNullOrEmpty(Request.QueryString["ComoditiesName"]))
        {
            search += "&ComoditiesName=" + Request.QueryString["ComoditiesName"];
            sql += " and ComoditiesName like '%" + Request.QueryString["ComoditiesName"] + "%' ";
        }
        if (!string.IsNullOrEmpty(Request.QueryString["Brand"]))
        {
            search += "&Brand=" + Request.QueryString["Brand"];
            sql += "  and Brand like '%" + Request.QueryString["Brand"] + "%' ";
        }
        if (!string.IsNullOrEmpty(Request.QueryString["modulbh"]))
        {
            search += "&modulbh=" + Common.FormatParameter(Request.QueryString["modulbh"]);
            sql += "  and modulbh like '%" + Request.QueryString["modulbh"] + "%' ";
        }
        if (!string.IsNullOrEmpty(Request.QueryString["FactNum"]))
        {
            search += "&FactNum=" + Request.QueryString["FactNum"];
            sql += "  and FactNum" + Request.QueryString["FactNum"];
        }
        if (!string.IsNullOrEmpty(Request.QueryString["countStock"]))
        {
            search += "&countStock=" + Request.QueryString["countStock"];
            sql += "  and countStock" + Request.QueryString["countStock"];
        }
        sql += " order BY stockId DESC";
        //Response.Write(sql);
        //Response.End();
        PageNavigator1.Url = "../selectprice/PSelectPrice.aspx?moduid=" + Request.QueryString["moduid"] + search;
        PageNavigator1.Total = 1;
        PageNavigator1.Query = sql;

    }
    protected void GvData_RowDataBound(object sender, GridViewRowEventArgs e)//在邦定数据
    {
        //f.checkLevels(Request.Cookies["user"].Values["roleid"], hfxs.Value, 4, GvDataType, btndel, btnallflag, btnAdd);//权限
        if (f.GetTableValue("CS_Param", "IsPrice", "1=1") != "1")
        {
            GvData.Columns[8].Visible = false;
        }
        if (f.GetTableValue("CS_Param", "IsrestPrice", "1=1") != "1")
        {
            GvData.Columns[7].Visible = false;
        }

    }
    protected void btnSearch_Click(object sender, EventArgs e)//价格管理-查询
    {
        string search = "";
        if (!string.IsNullOrEmpty(ComoditiesType.Text))
        {
            search += "&ComoditiesType=" + ComoditiesType.Text;
        }
        if (!string.IsNullOrEmpty(Brand.Text))
        {
            search += "&Brand=" + Brand.Text;
        }
        if (!string.IsNullOrEmpty(ComoditiesName.Text))
        {
            search += "&ComoditiesName=" + Common.FormatParameter(ComoditiesName.Text);
        }
        if (!string.IsNullOrEmpty(Specifications.Text))
        {
            search += "&Specifications=" + Specifications.Text;
        }
        if (!string.IsNullOrEmpty(modulbh.Text))
        {
            search += "&modulbh=" + Common.FormatParameter(modulbh.Text);
        }
        if (!string.IsNullOrEmpty(FactNum.Text))
        {
            search += "&FactNum=" + FactNum.Text;
        }
        if (!string.IsNullOrEmpty(countStock.Text))
        {
            search += "&countStock=" + countStock.Text;
        }
        Response.Redirect("PSelectPrice.aspx.aspx?moduid=" + hfxs.Value + search);
    }
    protected void outExcel_Click(object sender, EventArgs e)//生成Excel
    {
        Response.Clear();
        Response.Buffer = true;
        Response.Charset = "GB2312";
        Response.AppendHeader("Content-Disposition", "attachment;filename=SelectPrice" + DateTime.Now.Date.ToString("yyyyMMdd") + ".xls");
        // 如果设置为 GetEncoding("GB2312");导出的文件将会出现乱码！！！
        Response.ContentEncoding = System.Text.Encoding.UTF7;
        Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。 
        System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
        //  turn off paging 

        StringWriter sw = new StringWriter();
        HtmlTextWriter htw = new HtmlTextWriter(sw);
        this.GvData.RenderControl(htw);
        string strHtml = sw.ToString().Trim();
        Response.Output.Write(strHtml);
        Response.Flush();
        Response.End();
        // turn the paging on again 

    }
    //添加一个空方法,防止   GridView”的控件“GridView1”必须放在具有 runat=server 的窗体标记内错误
    public override void VerifyRenderingInServerForm(Control control)
    {
        // Confirms that an HtmlForm. control is rendered for
    }


}
